import { defineStore } from "pinia";
import Mock from "mockjs"
const stationdata = Mock.mock({
  "list1|20":[
    {
      id:"@id",
      "staton":'@city',
      "flag|1":[true,false]
    }
  ],
  "list2|20": [
    {
      "id|+1": 1,
      "train|1": [`G71高铁`, "G985高铁"],
      startStation: "北京西-昆明南",
      lines:
        "① 北京西 → ② 石家庄 → ③ 郑州东 →  ④ 武汉 → ⑤ 长沙南 →  ⑥怀化南 → ⑦贵阳北 → ⑧ 昆明南",
      create_time: "@datetime",
      "flag|1":[true,false]
    },
  ],
  "list3|20": [
    {
      "id|+1": "@id",
      "date|1": ["2023-5-20","2023-5-21","2023-5-22"],
      "train|1": ["G71高铁", "Z49动车", "K599快速", "T145特快"],
      "startStation|1": ["北京西-昆明南", "北京西-南昌", "包头-广州"],
      "startTime|1": ["14:16-07:25", "17:18-11:48", "07:05-17:29"],
      "litime":"@time('H:m')"+'--'+'@cword("当一二三四五六七八九十", 1)'+'日到达',
      "seatType|1": ["软卧 200", "硬卧 185", "一等座 190", "商务座 320"],
      "subState|1": ['已提交', '未提交'],
      "flag|1": [false,true],
    },
  ],
  'list4|10': [{
    'id|+1': 1,
    'order|100000-999999': 0,
    name: '@cname',
    date: '@time(yyyy-MM-dd hh:mm:ss)',
    'trainNum|1': ['G71', 'Z49', 'T145', 'K599'],
    'type|1': ['高铁', '动车', '特快', '快速'],
    startCity: '@city',
    endCity: '@city',
    startTime: '@time(hh:mm)',
    endTime: '@time(hh:mm)',
    passenger: '@cname',
    departure: '@time(yyyy-MM-dd)',
    'price|100-500': 1,
    'carriage|1': ['02车09A号', '08车09D号', '03车02C号'],
    'status|1': ['已付款', '待付款', '已取消', '已取票'],
    'seatType|1': ['商务座', '一等座', '二等座']
}]
})
interface State {
  userList: UserInfo[];
  user: UserInfo | null;
  count: number;
  listcar: listcount[];
  station:ststioncount[]
  linedata:linecount[]
  ticketdata:tickcount[]
  orderList:any[]
}
export interface tickcount {
  id: number;
  train:string
  flag?: boolean
  startStation:string
  lines:string
  create_time:string
}
export interface linecount {
  id: number;
  train:string
  flag?: boolean
  startStation:string
  lines:string
  create_time:string
}
export interface ststioncount {
  id: number;
  station:string
  flag?: boolean
}
export interface listcount {
  id: number;
  cartype?: string;
  name?: string;
  allnum?: string;
  flag?: boolean;
  xiannum?: number;
  count?: 8;
  createdate?: string;
}
interface UserInfo {
  name: string;
  age: number;
}
export const useCounterStore = defineStore("counter", {
  state: (): State => ({
    userList: [],
    user: null,
    count: 0,
    listcar: [
      {
        id: 1,
        cartype: "G624",
        name: "Tom",
        allnum: "586",
        flag: true,
        xiannum: 646,
        count: 8,
        createdate: "2022-10-10 14:00:00",
      },
      {
        id: 2,
        cartype: "G627",
        name: "Tom1",
        allnum: "586",
        flag: false,
        xiannum: 646,
        count: 8,
        createdate: "2022-10-10 14:00:00",
      },
      {
        id: 3,
        cartype: "G627",
        name: "Tom1",
        allnum: "586",
        flag: true,
        xiannum: 646,
        count: 8,
        createdate: "2022-10-10 14:00:00",
      },
      {
        id: 4,
        cartype: "G627",
        name: "Tom1",
        allnum: "586",
        flag: true,
        xiannum: 646,
        count: 8,
        createdate: "2022-10-10 14:00:00",
      },
      {
        id: 5,
        cartype: "G627",
        name: "Tom1",
        allnum: "586",
        flag: false,
        xiannum: 646,
        count: 8,
        createdate: "2022-10-10 14:00:00",
      },
      {
        id: 6,
        cartype: "G627",
        name: "Tom1",
        allnum: "586",
        flag: true,
        xiannum: 646,
        count: 8,
        createdate: "2022-10-10 14:00:00",
      },
      {
        id: 7,
        cartype: "G624",
        name: "Tom",
        allnum: "586",
        flag: true,
        xiannum: 646,
        count: 8,
        createdate: "2022-10-10 14:00:00",
      },
      {
        id: 8,
        cartype: "G627",
        name: "Tom1",
        allnum: "586",
        flag: false,
        xiannum: 646,
        count: 8,
        createdate: "2022-10-10 14:00:00",
      },
      {
        id: 9,
        cartype: "G627",
        name: "Tom1",
        allnum: "586",
        flag: true,
        xiannum: 646,
        count: 8,
        createdate: "2022-10-10 14:00:00",
      },
      {
        id: 10,
        cartype: "G627",
        name: "Tom1",
        allnum: "586",
        flag: true,
        xiannum: 646,
        count: 8,
        createdate: "2022-10-10 14:00:00",
      },
      {
        id: 11,
        cartype: "G627",
        name: "Tom1",
        allnum: "586",
        flag: false,
        xiannum: 646,
        count: 8,
        createdate: "2022-10-10 14:00:00",
      },
      {
        id: 12,
        cartype: "G627",
        name: "Tom1",
        allnum: "586",
        flag: true,
        xiannum: 646,
        count: 8,
        createdate: "2022-10-10 14:00:00",
      }
      
    ],
    station:stationdata.list1,
    linedata:stationdata.list2,
    ticketdata:stationdata.list3,
    orderList:stationdata.list4,
  }),
  getters: {
    double: (state) => state.count * 2,
  },
  actions: {
    increment() {
      this.count++;
    },
    carnumdelete(actions: number){
     this.listcar.forEach((item,idx)=>{
      if(item.id === actions){
        this.listcar.splice(idx,1)
      }
     })
    },
    carnumedit(actions: any){
        console.log(actions,'123');
      this.listcar.forEach((item,idx)=>{
        
       if(item.id === actions.id){
         this.listcar.splice(idx,1,actions)
       }
      })
     },
    carnumsetflag(actions: number){
      this.listcar.forEach((item)=>{
        if(item.id === actions){
          item.flag =!item.flag
        }
       })
    },
    ststiondelete(actions: number){
      this.station.forEach((item,idx)=>{
        if(item.id === actions){
          this.station.splice(idx,1)
        }
       })
    },
    ststionsetflag(actions: number){
      this.station.forEach((item)=>{
        if(item.id === actions){
          item.flag =!item.flag
        }
       })
    },
    linedelete(actions: number){
      this.linedata.forEach((item,idx)=>{
        if(item.id === actions){
          this.linedata.splice(idx,1)
        }
       })
    },
    linesetflag(actions: number){
      this.linedata.forEach((item)=>{
        if(item.id === actions){
          item.flag =!item.flag
        }
       })
    },
    ticketdelete(actions: number){
      this.ticketdata.forEach((item,idx)=>{
        if(item.id === actions){
          this.ticketdata.splice(idx,1)
        }
       })
    },
    ticketflag(actions: number){
      this.ticketdata.forEach((item)=>{
        if(item.id === actions){
          item.flag =!item.flag
        }
       })
    }
  },
});
